1
|
|
View Code Duplication |
var assert = require('chai').assert, |
|
|
|
|
2
|
|
|
GedcomX = require('../../'); |
3
|
|
|
|
4
|
|
|
describe('Person', function(){ |
5
|
|
|
|
6
|
|
|
it('Create with JSON', function(){ |
7
|
|
|
var person = GedcomX.Person({ |
8
|
|
|
id: 'testPerson', |
9
|
|
|
private: true, |
10
|
|
|
living: true, |
11
|
|
|
gender: { |
12
|
|
|
type: 'http://gedcomx.org/Female' |
13
|
|
|
}, |
14
|
|
|
names: [ |
15
|
|
|
{ |
16
|
|
|
type: 'http://gedcomx.org/BirthName', |
17
|
|
|
nameForms: [ |
18
|
|
|
{ |
19
|
|
|
fullText: 'Joanna Hopkins' |
20
|
|
|
} |
21
|
|
|
] |
22
|
|
|
} |
23
|
|
|
], |
24
|
|
|
facts: [ |
25
|
|
|
{ |
26
|
|
|
type: 'http://gedcomx.org/Birth', |
27
|
|
|
date: { |
28
|
|
|
formal: '+2001-04-09' |
29
|
|
|
}, |
30
|
|
|
place: { |
31
|
|
|
original: 'Farm house' |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
], |
35
|
|
|
display: { |
36
|
|
|
"name" : "Joanna Hopkins", |
37
|
|
|
"gender" : "Female" |
38
|
|
|
} |
39
|
|
|
}); |
40
|
|
|
assert.equal(person.getLiving(), true); |
41
|
|
|
assert.equal(person.getId(), 'testPerson'); |
42
|
|
|
assert.equal(person.getPrivate(), true); |
43
|
|
|
assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female'); |
44
|
|
|
assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins'); |
45
|
|
|
assert.equal(person.getFacts()[0].getDate().getFormal(), '+2001-04-09'); |
46
|
|
|
assert.equal(person.getFacts()[0].getPlace().getOriginal(), 'Farm house'); |
47
|
|
|
assert.equal(person.getDisplay().getName(), 'Joanna Hopkins'); |
48
|
|
|
}); |
49
|
|
|
|
50
|
|
|
it('Build', function(){ |
51
|
|
|
var person = GedcomX.Person() |
52
|
|
|
.setId('testPerson') |
53
|
|
|
.setLiving(true) |
54
|
|
|
.setPrivate(true) |
55
|
|
|
.setGender(GedcomX.Gender().setType('http://gedcomx.org/Female')) |
56
|
|
|
.addName(GedcomX.Name().addNameForm(GedcomX.NameForm().setFullText('Joanna Hopkins'))) |
57
|
|
|
.addFact(GedcomX.Fact().setDate(GedcomX.Date().setFormal('+2001-04-09')).setPlace(GedcomX.PlaceReference().setOriginal('Farm house'))) |
58
|
|
|
.setDisplay(GedcomX.DisplayProperties().setName("Joanna Hopkins").setGender("Female")); |
59
|
|
|
assert.equal(person.getLiving(), true); |
60
|
|
|
assert.equal(person.getId(), 'testPerson'); |
61
|
|
|
assert.equal(person.getPrivate(), true); |
62
|
|
|
assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female'); |
63
|
|
|
assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins'); |
64
|
|
|
assert.equal(person.getFacts()[0].getDate().getFormal(), '+2001-04-09'); |
65
|
|
|
assert.equal(person.getFacts()[0].getPlace().getOriginal(), 'Farm house'); |
66
|
|
|
assert.equal(person.getDisplay().getName(), 'Joanna Hopkins'); |
67
|
|
|
}); |
68
|
|
|
|
69
|
|
|
it('toJSON', function(){ |
70
|
|
|
var data = { |
71
|
|
|
id: 'testPerson', |
72
|
|
|
private: true, |
73
|
|
|
gender: { |
74
|
|
|
type: 'http://gedcomx.org/Female' |
75
|
|
|
}, |
76
|
|
|
names: [ |
77
|
|
|
{ |
78
|
|
|
type: 'http://gedcomx.org/BirthName', |
79
|
|
|
nameForms: [ |
80
|
|
|
{ |
81
|
|
|
fullText: 'Joanna Hopkins' |
82
|
|
|
} |
83
|
|
|
] |
84
|
|
|
} |
85
|
|
|
], |
86
|
|
|
facts: [ |
87
|
|
|
{ |
88
|
|
|
type: 'http://gedcomx.org/Birth', |
89
|
|
|
date: { |
90
|
|
|
formal: '+2001-04-09' |
91
|
|
|
}, |
92
|
|
|
place: { |
93
|
|
|
original: 'Farm house' |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
], |
97
|
|
|
display: { |
98
|
|
|
"name" : "Joanna Hopkins", |
99
|
|
|
"gender" : "Female" |
100
|
|
|
} |
101
|
|
|
}, person = GedcomX.Person(data); |
102
|
|
|
assert.deepEqual(person.toJSON(), data); |
103
|
|
|
}); |
104
|
|
|
|
105
|
|
|
}); |